/*
 * @Author: jiansheng
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
if (!window.VueRouter) Vue.use(VueRouter)

/**
 * meta 中的属性
 *
 * @param {Boolean} hideFooter 是否需要隐藏底部，默认为 false, 需要隐藏的话 设置为 true
 * @param {Boolean} hideHeader 是否需要隐藏头部，默认为 false, 需要隐藏的话 设置为 true
 * @param {Boolean} auth       是否需要验证登录权限，需要的话 设置为 true
 */

const routes = [
  {
    path: '/',
    meta: { title: '数据汇总', hideHeader: true, hideFooter: true },
    component: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue')
  },
  {
    path: '/det',
    meta: { title: '详情', hideHeader: true, hideFooter: true },
    component: () => import(/* webpackChunkName: "home" */ '../views/det/det.vue')
  }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'hash',
  routes
})

router.beforeEach((to, from, next) => {
  next()
})
router.afterEach((to, from) => {
  let a = document.querySelector('#app')
  if (a) a.scrollTop = 0
})

export default router
